#include "audio_file_flac.h"

#include <cstring>
#include <iostream>
#include <fstream>

#include "FLAC++/metadata.h"

namespace plok {


    Audio_file_flac::Audio_file_flac(std::string fileName) : Audio_file(fileName)
    {

        FLAC::Metadata::Chain chain;
        if (chain.is_valid()) {
            if (chain.read(fileName.c_str())) {

                FLAC::Metadata::Iterator iterator;
                iterator.init(chain);

                while (iterator.next()) {
                    switch (iterator.get_block_type()) {
                        case FLAC__METADATA_TYPE_VORBIS_COMMENT: {
                            FLAC::Metadata::Prototype * block = iterator.get_block();

                            FLAC::Metadata::VorbisComment * vComment = dynamic_cast<FLAC::Metadata::VorbisComment *> (block);


                            for (unsigned i = 0; i < vComment->get_num_comments(); i++) {
//                            qDebug() << "nr: " << i << " coments: " << vComment->get_comment(i).get_field_name() << " " << vComment->get_comment(i).get_field_value();
                            }
                            delete block;
                            break;
                        }
                        default:
                            break;
                    }
                }
            }
        } else {
            //qDebug() << "no flac";
        }

    }
}
